<template>
	<div class="m_r">
		<header class="top_bar">
		    <a onclick="window.history.go(-1)" class="icon_back"></a>
		    <h3 class="cartname">京东注册</h3>
		</header>
		<main class="user_login_box">
		    <div class="login_dialog">
		        <div class="_username">
		            <input type="text" name="regname" placeholder="用户名/邮箱/手机号" class="user_input" v-model="regname">
		        </div>
		        <div class="_username u_passwd">
		            <input type="password" name="regpasswd" placeholder="请输入密码" class="user_input" v-model="regpasswd">
		        </div>
		        <div class="_username u_passwd">
		            <input type="password" name="regpasswd_ag" placeholder="请再次输入密码" class="user_input" v-model="regpasswd_ag">
		        </div>
				<mu-flex style="z-inxex:1002" justify-content="center" align-items="center">
					<mu-button @click="goSearch" full-width color="primary">注册</mu-button>
				</mu-flex>
				<div v-if="loginFlag">
		            <!-- <router-link style="cursor:pointer" tag="span" to="/login">去登陆</router-link> -->
					<!-- <mu-flex justify-content="center" align-items="center"> -->
					<mu-button @click="goSearch1" flat color="primary">去登陆</mu-button>
				<!-- </mu-flex> -->
		        </div>
				
		    </div>
		</main>
	</div>
</template>
<script>
	export default {
		data(){
			return{
				regname:'',
				regpasswd:'',
				regpasswd_ag:'',
				regInfo:{},
				loginFlag: false
			}
		},
		methods:{
			goSearch(){
				if(this.regname ==''){
					alert('请输入手机号');
				}else if(this.regpasswd == '' || this.regpasswd_ag == ''){
					alert('请输入密码');
				}else if(this.regpasswd!==this.regpasswd_ag){
					alert('两次输入的密码不一致');
				}else{
					this.$axios.post('/reg',{
						regName:this.regname,
						regPasswd:this.regpasswd
				}).then((res)=>{
					console.log('res', res)
					if (res.status === 1) {
						// this.$message.success(res.msg)
						this.$toast.success({
								position: 'top',
								message: res.msg
							});
						this.$router.push('/login')
					}else if (res.status === 506) {
						//reg success, go to this login page
						// window.history.go(-1);
						// this.$message.error(res.msg)
						this.$toast.message({
								position: 'top',
								message: res.msg
							});
						this.loginFlag = true
					} else {
						this.$toast.error({
								position: 'top',
								message: res.msg
							});
					}
				},(err)=>{
					console.log(err);
				});
				}
				
			},
			goSearch1 () {
				this.$router.push('/login')
			}
		}
	}
</script>
<style lang="scss" scoped>
@import '../assets/css/reg.css';
/deep/ .mu-ripple-wrapper,.mu-button-full-width {
	z-index: 1002
}
</style>